Conversation
18028ae to
23ca480
Compare
| // Argument (Canister) | ||
| let args::Canister::Name(name) = &args.canister else { | ||
| return Err(CommandError::Args); | ||
| }; |
There was a problem hiding this comment.
I don't think we should forbid using principals in projects. Otherwise to talk to a specific canister on a non-default network one has to somehow hook up the principal to a name just for one-off calls
|
|
||
| // Ensure canister is included in the environment | ||
| if !env.canisters.contains_key(&args.name) { | ||
| if !env.canisters.contains_key(name) { |
There was a problem hiding this comment.
Similarly, this should probably only happen if a non-principal was supplied
| #[error("an invalid argument was provided")] | ||
| Args, |
There was a problem hiding this comment.
I don't think this is enough detail to give a decent user experience. It's ok to leave this as-is, but at least make a ticket to improve the situation. We can easily say 'only provide one of network and environment, not both' here
| // #[cfg(test)] | ||
| // pub(crate) trait IntoOptions<T> { | ||
| // fn into_options(self) -> Vec<Option<T>>; | ||
| // } | ||
|
|
||
| // #[cfg(test)] | ||
| // impl<T> IntoOptions<T> for Vec<T> { | ||
| // fn into_options(self) -> Vec<Option<T>> { | ||
| // self.into_iter().fold(vec![None], |mut acc, cur| { | ||
| // acc.push(Some(cur)); | ||
| // acc | ||
| // }) | ||
| // } | ||
| // } | ||
|
|
||
| pub(crate) fn all_modes() -> Vec<Mode> { | ||
| vec![Mode::Global, Mode::Project("dir".into())] | ||
| } | ||
|
|
||
| // pub(crate) fn all_networks() -> Vec<args::Network> { | ||
| // vec![ | ||
| // args::Network::Name("my-network".to_string()), | ||
| // args::Network::Url("http::/www.example.com".to_string()), | ||
| // ] | ||
| // } |
There was a problem hiding this comment.
| // #[cfg(test)] | |
| // pub(crate) trait IntoOptions<T> { | |
| // fn into_options(self) -> Vec<Option<T>>; | |
| // } | |
| // #[cfg(test)] | |
| // impl<T> IntoOptions<T> for Vec<T> { | |
| // fn into_options(self) -> Vec<Option<T>> { | |
| // self.into_iter().fold(vec![None], |mut acc, cur| { | |
| // acc.push(Some(cur)); | |
| // acc | |
| // }) | |
| // } | |
| // } | |
| pub(crate) fn all_modes() -> Vec<Mode> { | |
| vec![Mode::Global, Mode::Project("dir".into())] | |
| } | |
| // pub(crate) fn all_networks() -> Vec<args::Network> { | |
| // vec![ | |
| // args::Network::Name("my-network".to_string()), | |
| // args::Network::Url("http::/www.example.com".to_string()), | |
| // ] | |
| // } | |
| pub(crate) fn all_modes() -> Vec<Mode> { | |
| vec![Mode::Global, Mode::Project("dir".into())] | |
| } | |
| } | ||
|
|
||
| const PLEASE_PROVIDE_A_CANISTER_PRINCIPAL_IN_GLOBAL_MODE: &str = r#" | ||
| Please provide a canister principal in global mode. |
There was a problem hiding this comment.
Not convinced this is the best wording. global mode makes me think of a flag that I could use to switch to local mode.
| Please provide a canister principal in global mode. | |
| {user_provided_string} is not a principal. Cannot use non-principals outside of a project. |
| } | ||
|
|
||
| const ENVIRONMENTS_ARE_NOT_AVAILABLE_IN_GLOBAL_MODE: &str = r#" | ||
| Environments are not available in global mode. |
There was a problem hiding this comment.
| Environments are not available in global mode. | |
| Environments are not available in outside of projects. |
| } | ||
|
|
||
| const A_NETWORK_URL_IS_REQUIRED_IN_GLOBAL_MODE: &str = r#" | ||
| A network `url` is required in global mode. |
There was a problem hiding this comment.
| A network `url` is required in global mode. | |
| A network `url` is required outside of a project. |
|
We moved away from this approach because it uses icp.yaml to decide the mode. Instead of adopted an approach where we decide the mode based on the command and arguments provided. |
This change introduces a few new things:
icpprojects. This allows us to:The above are done for several initial commands, with the assumption that the same work can take place for the rest of the cli footprint (currently global mode and arg validation is implemented for
icp canister start/stopandtoken transfer/balance).